//
//  KZUserCenterVC.m
//  听说弱点强化训练
//
//  Created by 朱凯 on 2018/9/4.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "KZUserCenterVC.h"

// vc
#import "KZUserMyNewWordVC.h"
#import "LSWrongBookController.h"
#import "KZHomeTestVC.h"
// view
#import "KZUserHeaderView.h"

// cell


// test
#import "KZUnfamiliarVocabularyImproveVC_version2.h"

@interface KZUserCenterVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, copy  ) NSArray *items;

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) KZUserHeaderView *headerView;
@end

@implementation KZUserCenterVC

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self addLeftBackBarButtonItem];
    
    [self createTableView];
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self setNaviAttributeWithTranslucent:true stateBarLightContent:true];
    self.navigationController.navigationBar.hidden = true;
}

#pragma mark - 创建视图
- (void)createTableView {
    
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    self.table.separatorColor = [UIColor colorWithWhite:0.9 alpha:1];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0)).priorityMedium();
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-0);
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        }
    }];
    
    _headerView = [[KZUserHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 750.0 * 286.0)];
    _table.tableHeaderView = _headerView;
    
    
    [_table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.items[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"kz-%@", self.items[indexPath.section][indexPath.row]]];
    cell.textLabel.text = self.items[indexPath.section][indexPath.row];
    cell.textLabel.font = FONT(14);
    if (indexPath.section == 0) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return UIView.new;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            KZUserMyNewWordVC *vc = [KZUserMyNewWordVC new];
            [self push:vc];
        } else if (indexPath.row==1) {
            LSWrongBookController *vc  = [LSWrongBookController new];
            [self push:vc];
        }
    } else {
        if (indexPath.row == 0) {
            [self dismissViewControllerAnimated:true completion:nil];
        }
        if (indexPath.row == 1) {
//            KZHomeTestVC *vc = [KZHomeTestVC new];
//            [self push:vc];
//            return;
            
            Authentication *auth = [[Authentication alloc]init];
            NSInteger info = [auth logOut];
            NSLog(@"logout=====%ld",(long)info);
            [((AppDelegate *)[UIApplication sharedApplication].delegate) setupLoginViewController];
        }
    }
}

#pragma mark - getter
- (NSArray *)items {
    
    if (!_items) {
        _items = @[@[@"我的生词本", @"我的错题本"], @[@"返回系统首页", @"退出登录"]];
    }
    return _items;
}


//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//
//    KZUnfamiliarVocabularyImproveVC_version2 *vc = [KZUnfamiliarVocabularyImproveVC_version2 new];
//    [self push:vc];
//}
@end
